//
//  AlamofireViewController.swift
//  SwiftStudy3.0
//
//  Created by mal on 17/2/13.
//  Copyright © 2017年 maliang. All rights reserved.
//

import UIKit
import Alamofire
import SwiftyJSON
import TTReflect

let testUrl = "http://mobile.ximalaya.com/mobile/discovery/v2/recommends?channel=ios-b1&device=iPhone&includeActivity=true&includeSpecial=true&scale=2&version=4.3.38"
let testUrl1 = "http://mobile.ximalaya.com/mobile/others/album/track?albumId=266276&device=iPhone&pageSize=20&position=1&source=1&title=%E7%8C%9C%E4%BD%A0%E5%96%9C%E6%AC%A2&trackId=30815386"

class AlamofireViewController: MMenuItem {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.defaultRequest()
        // Do any additional setup after loading the view.
    }
    
    func defaultRequest() -> Void {
        
        Alamofire.request(testUrl1, method: .get, parameters: nil).responseJSON { (response:Alamofire.DataResponse<Any>) in
            
            if let resDic = response.result.value{
                
                let json = JSON(resDic)
                let album = json["album"].dictionaryObject
                let albumModel = Reflect<AlbumModel>.mapObject(json: album as AnyObject?)
                print("albumID = \(albumModel.category)")
            }
            else{
            
            }
        }
    }
    
    override class func menuitem() -> MMenuItem?{
        
        return AlamofireViewController.init(nibName: nil, bundle: nil)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

class AlbumModel: NSObject {
    
    var albumId:Int = 0
    var categoryId:Int = 0
    var category:String = ""
    
    func setupMappingReplaceProperty() -> [String : String] {
        return ["category": "categoryName"]
    }
}
